<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="t" %>

<t:body title="Редактивование профиля">

    <c:choose>
    	<c:when test="${user.id ne -1}">
   	    	<c:url value="/user/${user.id}/edit" var="url"/>
    	</c:when>
    	<c:otherwise>
   	    	<c:url value="/user/new" var="url"/>
    	</c:otherwise>
    </c:choose>
		<div class="form_block">
			<form:form modelAttribute="user" enctype="multipart/form-data" acceptCharset="UTF-8" action="${url}">
				<fmt:formatDate value="${user.dateOfBirth}" pattern="dd.MM.yyyy" var="dateOfBirth" />
				<fmt:formatDate value="${user.dateOfExpulsion}" pattern="dd.MM.yyyy" var="dateOfExpulsion" />
				<fmt:formatDate value="${user.dateAccepted}" pattern="dd.MM.yyyy" var="dateOfAccepted" />
				
				<t:section cssClass="info">Личные данные</t:section>
					
					<t:input name="Фамилия *" path="user.lastName">
						<form:input path="lastName" size="20" maxlength="20" />
					</t:input>
					
					<t:input name="Имя *" path="user.firstName">
						<form:input path="firstName" size="20" maxlength="20" />
					</t:input>
					
					<t:input name="Отчество" path="user.patrName">
						<form:input path="patrName" size="20" maxlength="20" />
					</t:input>
					
					<t:input name="Логин *" path="user.login">
						<form:input path="login" size="20" maxlength="20" />
					</t:input>
					
					<t:input name="E-mail адрес" path="user.mail">
						<form:input path="mail" size="20" maxlength="20" />
					</t:input>
				
					<t:input name="Дата рождения" path="user.dateOfBirth">
						<input type="text" name="dateOfBirth" value="${dateOfBirth}" size="10" maxlength="10" class="date_input"/>
					</t:input>
										
					<t:input name="Номер телефона" path="user.phoneNumber">
						<form:input path="phoneNumber" size="15" maxlength="15" />
					</t:input>
					
					<div class="photo_block form_row">
						<div class="left_side">Фото(1 мб максимум)</div>
						<div class="right_side"><input type="file" name="photoFile" class="file_input" border="0"></div>
					</div>

				<t:section cssClass="role">Описание</t:section>
				
					<t:input name="Студент" path="user.student">
						<form:checkbox path="student" onclick="slide('.student_block', !$(this).attr('checked'), 'slow');"/>
					</t:input>
					
					<t:input name="Преподаватель" path="user.professor">
						<form:checkbox path="professor" />
					</t:input>
					
					<t:input name="Админ" path="user.admin">
						<form:checkbox path="admin" />
					</t:input>
				
				<div class="${user.student ? '' : 'hiden '}student_block" style="float: left;">
					<t:section cssClass="student">Студент</t:section>
				
					<t:input name="Характеристика" path="user.testimonial">
						<form:textarea path="testimonial" cols="30" rows="5"/>
					</t:input>
					
					<t:input name="Группа в университете" path="user.universityGroup">
						<form:input path="universityGroup" size="20" maxlength="20" />
					</t:input>
					
					<t:input name="Год выпуска" path="user.graduationYear">
						<form:input path="graduationYear" size="4" maxlength="4" />
					</t:input>
					
					<t:input name="Группа *" path="user.group">
						<form:select path="group">
							<form:option value="">&nbsp</form:option>
							<form:options items="${groups}" itemValue="id" />
						</form:select>
					</t:input>
					
					<t:input name="Статус" path="user.status">
						<form:select path="status" items="${statuses}"
							itemLabel="caption" id="status" cssClass="status_link" onchange="display('.on_expulsion', $(this).val() == 'EXPULSION');"/>
					</t:input>
					<div class="${user.status.caption eq 'Отчислен' ? '' : 'hiden '}on_expulsion"  style="float: left;">
						<t:input name="Дата отчисления" path="user.dateOfExpulsion">
							<input type="text" name="dateOfExpulsion" value="${dateOfExpulsion}" size="10" maxlength="10" class="date_input"/>
						</t:input>
					</div>
					
					<t:input name="Принят в ПрофИТсофт" path="user.accepted">
						<form:checkbox path="accepted" onclick="replace('.on_accepted', '.on_not_accepted', $(this).attr('checked'));"/>
					</t:input>
				
					<div class="${user.accepted ? '' : 'hiden '}on_accepted"  style="float: left;">
						<t:input name="Дата принятия" path="user.dateOfExpulsion">
							<input type="text" name="dateAccepted" value="${dateOfAccepted}" size="10" maxlength="10" class="date_input on_accept"/>
						</t:input>
					</div>								
								
					<div class="${user.accepted ? 'hiden ' : ''}on_not_accepted"  style="float: left;">
						<t:input name="Текушее место работы" path="user.currentPlaceOfEmployment">
							<form:input path="currentPlaceOfEmployment" size="20" cssClass="on_not_accept"/>
						</t:input>
					</div>
					
				</div>
				
				
				<div class="form_section ${cssClass}"><div class="form_section_text" onclick="slide('.change_passwor_block', $('.change_passwor_block').css('display') != 'none', 'fast');">Изменение пароля</div></div>
				<spring:bind path="password">
					<div class="${status.error ? 'change_passwor_block' : 'change_passwor_block hiden'}" style="float: left;">
						<c:if test="${status.error}">
							<div class="form_error_row">
								<c:forEach  items="${status.errorMessages}" var="msg" >
									<span class="error_message"><c:out value="${msg}"/><br/></span>
								</c:forEach>
							</div>
						</c:if>
						<c:if test="${user.id ne -1}">
							<div class="form_row">
								<div class="left_side">Старый пароль</div>
								<div class="right_side"><input type="password" name="oldPassword" size="20"	maxlength="20" /></div>
							</div>	
						</c:if>
						<div class="form_row">
							<div class="left_side">Новый пароль</div>
							<div class="right_side"><form:password path="password" size="20" maxlength="20" /></div>
						</div>	
						<div class="form_row">
							<div class="left_side">А ну еще разок</div>
							<div class="right_side"><input type="password" name="rePassword" size="20" maxlength="20"/></div>
						</div>	
					</div>
				</spring:bind>
				
			</form:form>
			<span class="link" onclick="document.forms[0].submit();" style="paddind: 5px 15px;">Сохранить</span>
			<span class="link" onclick="history.back()">Назад</span>
		</div>
		<br/>
</t:body>